package com.dks.exception;

import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSONObject;
import com.dks.result.Result;
import com.dks.result.ResultInfo;
import com.dks.result.ResultModel;
import lombok.extern.slf4j.Slf4j;

/**
 * @author evan
 * @date 2020/4/16
 */
@Slf4j
@ControllerAdvice
public class GlobalExceptionHandler {

    @ResponseBody
    @ExceptionHandler(BaseException.class)
    public String baseExceptionHandler(BaseException e) {
        //TODO 记录异常日志
        e.printStackTrace();
        return JSONObject.toJSONString(Result.makeResult(e.getResultInfo()));
    }

    @ResponseBody
    @ExceptionHandler(Exception.class)
    public ResultModel exceptionHandler(Exception e){
        //TODO 记录异常日志
        e.printStackTrace();
        return Result.makeResult(ResultInfo.EXCEPTION, e.getMessage());
    }
}
